// $ANTLR 3.3 Nov 30, 2010 12:45:30 C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g 2012-06-26 07:38:48

package org.moflon.moca.txt.unparser;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;
import java.util.HashMap;
public class TxtTreeGrammar extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "STRING", "ATTRIBUTE", "'BOARD'", "'ROW'", "'FIELD'"
    };
    public static final int EOF=-1;
    public static final int T__7=7;
    public static final int T__8=8;
    public static final int T__9=9;
    public static final int ID=4;
    public static final int STRING=5;
    public static final int ATTRIBUTE=6;

    // delegates
    // delegators


        public TxtTreeGrammar(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public TxtTreeGrammar(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected StringTemplateGroup templateLib =
      new StringTemplateGroup("TxtTreeGrammarTemplates", AngleBracketTemplateLexer.class);

    public void setTemplateLib(StringTemplateGroup templateLib) {
      this.templateLib = templateLib;
    }
    public StringTemplateGroup getTemplateLib() {
      return templateLib;
    }
    /** allows convenient multi-value initialization:
     *  "new STAttrMap().put(...).put(...)"
     */
    public static class STAttrMap extends HashMap {
      public STAttrMap put(String attrName, Object value) {
        super.put(attrName, value);
        return this;
      }
      public STAttrMap put(String attrName, int value) {
        super.put(attrName, new Integer(value));
        return this;
      }
    }

    public String[] getTokenNames() { return TxtTreeGrammar.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g"; }


    public static class main_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "main"
    // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:22:1: main : ^( 'BOARD' (rows+= row )* ) -> board(rows=$rows);
    public final TxtTreeGrammar.main_return main() throws RecognitionException {
        TxtTreeGrammar.main_return retval = new TxtTreeGrammar.main_return();
        retval.start = input.LT(1);

        List list_rows=null;
        RuleReturnScope rows = null;
        try {
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:22:5: ( ^( 'BOARD' (rows+= row )* ) -> board(rows=$rows))
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:22:7: ^( 'BOARD' (rows+= row )* )
            {
            match(input,7,FOLLOW_7_in_main76); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:22:21: (rows+= row )*
                loop1:
                do {
                    int alt1=2;
                    int LA1_0 = input.LA(1);

                    if ( (LA1_0==8) ) {
                        alt1=1;
                    }


                    switch (alt1) {
                	case 1 :
                	    // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:22:21: rows+= row
                	    {
                	    pushFollow(FOLLOW_row_in_main80);
                	    rows=row();

                	    state._fsp--;

                	    if (list_rows==null) list_rows=new ArrayList();
                	    list_rows.add(rows.getTemplate());


                	    }
                	    break;

                	default :
                	    break loop1;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }


            // TEMPLATE REWRITE
            // 23:5: -> board(rows=$rows)
            {
                retval.st = templateLib.getInstanceOf("board",
              new STAttrMap().put("rows", list_rows));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "main"

    public static class row_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "row"
    // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:25:1: row : ^( 'ROW' (fields+= field )* ) -> row(fields=$fields);
    public final TxtTreeGrammar.row_return row() throws RecognitionException {
        TxtTreeGrammar.row_return retval = new TxtTreeGrammar.row_return();
        retval.start = input.LT(1);

        List list_fields=null;
        RuleReturnScope fields = null;
        try {
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:25:4: ( ^( 'ROW' (fields+= field )* ) -> row(fields=$fields))
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:25:6: ^( 'ROW' (fields+= field )* )
            {
            match(input,8,FOLLOW_8_in_row106); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:25:20: (fields+= field )*
                loop2:
                do {
                    int alt2=2;
                    int LA2_0 = input.LA(1);

                    if ( (LA2_0==9) ) {
                        alt2=1;
                    }


                    switch (alt2) {
                	case 1 :
                	    // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:25:20: fields+= field
                	    {
                	    pushFollow(FOLLOW_field_in_row110);
                	    fields=field();

                	    state._fsp--;

                	    if (list_fields==null) list_fields=new ArrayList();
                	    list_fields.add(fields.getTemplate());


                	    }
                	    break;

                	default :
                	    break loop2;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }


            // TEMPLATE REWRITE
            // 26:5: -> row(fields=$fields)
            {
                retval.st = templateLib.getInstanceOf("row",
              new STAttrMap().put("fields", list_fields));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "row"

    public static class field_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "field"
    // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:28:1: field : ^( 'FIELD' (figure= STRING )? ) -> field(figure=$figure);
    public final TxtTreeGrammar.field_return field() throws RecognitionException {
        TxtTreeGrammar.field_return retval = new TxtTreeGrammar.field_return();
        retval.start = input.LT(1);

        CommonTree figure=null;

        try {
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:28:6: ( ^( 'FIELD' (figure= STRING )? ) -> field(figure=$figure))
            // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:28:8: ^( 'FIELD' (figure= STRING )? )
            {
            match(input,9,FOLLOW_9_in_field137); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:28:18: (figure= STRING )?
                int alt3=2;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==STRING) ) {
                    alt3=1;
                }
                switch (alt3) {
                    case 1 :
                        // C:\\Users\\roland\\mbse_workspace_ex3\\ModelToTree\\src\\org\\moflon\\moca\\txt\\unparser\\TxtTreeGrammar.g:28:19: figure= STRING
                        {
                        figure=(CommonTree)match(input,STRING,FOLLOW_STRING_in_field142); 

                        }
                        break;

                }


                match(input, Token.UP, null); 
            }


            // TEMPLATE REWRITE
            // 29:3: -> field(figure=$figure)
            {
                retval.st = templateLib.getInstanceOf("field",
              new STAttrMap().put("figure", figure));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "field"

    // Delegated rules


 

    public static final BitSet FOLLOW_7_in_main76 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_row_in_main80 = new BitSet(new long[]{0x0000000000000108L});
    public static final BitSet FOLLOW_8_in_row106 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_field_in_row110 = new BitSet(new long[]{0x0000000000000208L});
    public static final BitSet FOLLOW_9_in_field137 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_STRING_in_field142 = new BitSet(new long[]{0x0000000000000008L});

}